<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Agile Modbus: /home/runner/work/agile_modbus/agile_modbus/src/agile_modbus_tcp.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Agile Modbus
   &#160;<span id="projectnumber">1.1.4</span>
   </div>
   <div id="projectbrief">Lightweight modbus protocol stack.</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('agile__modbus__tcp_8c_source.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">agile_modbus_tcp.c</div>  </div>
</div><!--header-->
<div class="contents">
<a href="agile__modbus__tcp_8c.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160; </div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="agile__modbus_8h.html">agile_modbus.h</a>&quot;</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160; </div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="preprocessor">#if AGILE_MODBUS_USING_TCP</span></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160; </div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="agile__modbus__tcp_8h.html">agile_modbus_tcp.h</a>&quot;</span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160; </div>
<div class="line"><a name="l00034"></a><span class="lineno"><a class="line" href="group___t_c_p___private___functions.html#ga5368e75a4d452b51ba973e5cef464752">   34</a></span>&#160;<span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="group___t_c_p___private___functions.html#ga5368e75a4d452b51ba973e5cef464752">agile_modbus_tcp_set_slave</a>(<a class="code" href="structagile__modbus.html">agile_modbus_t</a> *ctx, <span class="keywordtype">int</span> slave)</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;{</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;    ctx-&gt;<a class="code" href="structagile__modbus.html#acd02aacf2081b397ee378e21858b2dd7">slave</a> = slave;</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;    <span class="keywordflow">return</span> 0;</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;}</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160; </div>
<div class="line"><a name="l00049"></a><span class="lineno"><a class="line" href="group___t_c_p___private___functions.html#ga83bcbff089bd342862ecaf44d9bf2e47">   49</a></span>&#160;<span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="group___t_c_p___private___functions.html#ga83bcbff089bd342862ecaf44d9bf2e47">agile_modbus_tcp_build_request_basis</a>(<a class="code" href="structagile__modbus.html">agile_modbus_t</a> *ctx, <span class="keywordtype">int</span> <span class="keyword">function</span>,</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;                                                <span class="keywordtype">int</span> addr, <span class="keywordtype">int</span> nb,</div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;                                                uint8_t *req)</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;{</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;    <a class="code" href="structagile__modbus__tcp.html">agile_modbus_tcp_t</a> *ctx_tcp = ctx-&gt;<a class="code" href="structagile__modbus.html#ae1ab077d16f51a6dbaaa5e3136cf6053">backend_data</a>;</div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160; </div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;    <span class="comment">/* Increase transaction ID */</span></div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;    <span class="keywordflow">if</span> (ctx_tcp-&gt;<a class="code" href="structagile__modbus__tcp.html#a5e7cd9a4f62bbcade736030cea7f0f56">t_id</a> &lt; UINT16_MAX)</div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;        ctx_tcp-&gt;<a class="code" href="structagile__modbus__tcp.html#a5e7cd9a4f62bbcade736030cea7f0f56">t_id</a>++;</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;    <span class="keywordflow">else</span></div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;        ctx_tcp-&gt;<a class="code" href="structagile__modbus__tcp.html#a5e7cd9a4f62bbcade736030cea7f0f56">t_id</a> = 0;</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;    req[0] = ctx_tcp-&gt;<a class="code" href="structagile__modbus__tcp.html#a5e7cd9a4f62bbcade736030cea7f0f56">t_id</a> &gt;&gt; 8;</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;    req[1] = ctx_tcp-&gt;<a class="code" href="structagile__modbus__tcp.html#a5e7cd9a4f62bbcade736030cea7f0f56">t_id</a> &amp; 0x00ff;</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160; </div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;    <span class="comment">/* Protocol Modbus */</span></div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;    req[2] = 0;</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;    req[3] = 0;</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160; </div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;    <span class="comment">/* Length will be defined later by set_req_length_tcp at offsets 4</span></div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;<span class="comment">       and 5 */</span></div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160; </div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;    req[6] = ctx-&gt;<a class="code" href="structagile__modbus.html#acd02aacf2081b397ee378e21858b2dd7">slave</a>;</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;    req[7] = <span class="keyword">function</span>;</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;    req[8] = addr &gt;&gt; 8;</div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;    req[9] = addr &amp; 0x00ff;</div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;    req[10] = nb &gt;&gt; 8;</div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;    req[11] = nb &amp; 0x00ff;</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160; </div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="group___t_c_p___exported___constants.html#gac012bade0617291b78e007393f72b2e8">AGILE_MODBUS_TCP_PRESET_REQ_LENGTH</a>;</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;}</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160; </div>
<div class="line"><a name="l00086"></a><span class="lineno"><a class="line" href="group___t_c_p___private___functions.html#ga8fb22cc4a73e636d6bb6593d0e60f59c">   86</a></span>&#160;<span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="group___t_c_p___private___functions.html#ga8fb22cc4a73e636d6bb6593d0e60f59c">agile_modbus_tcp_build_response_basis</a>(<a class="code" href="structagile__modbus__sft.html">agile_modbus_sft_t</a> *sft, uint8_t *rsp)</div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;{</div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;    <span class="comment">/* Extract from MODBUS Messaging on TCP/IP Implementation</span></div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;<span class="comment">       Guide V1.0b (page 23/46):</span></div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;<span class="comment">       The transaction identifier is used to associate the future</span></div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;<span class="comment">       response with the request. */</span></div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;    rsp[0] = sft-&gt;<a class="code" href="structagile__modbus__sft.html#aea219d53ef291aa545de54ed04ecc639">t_id</a> &gt;&gt; 8;</div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;    rsp[1] = sft-&gt;<a class="code" href="structagile__modbus__sft.html#aea219d53ef291aa545de54ed04ecc639">t_id</a> &amp; 0x00ff;</div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160; </div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;    <span class="comment">/* Protocol Modbus */</span></div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;    rsp[2] = 0;</div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;    rsp[3] = 0;</div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160; </div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;    <span class="comment">/* Length will be set later by send_msg (4 and 5) */</span></div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160; </div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;    <span class="comment">/* The slave ID is copied from the indication */</span></div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;    rsp[6] = sft-&gt;<a class="code" href="structagile__modbus__sft.html#ab9ada92752df1ac2d7597a43eb1cd374">slave</a>;</div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;    rsp[7] = sft-&gt;<a class="code" href="structagile__modbus__sft.html#afe1918bcff8e86066656a68de876b873">function</a>;</div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160; </div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="group___t_c_p___exported___constants.html#ga3e02eaed8e08d8e34bccdd785fa09da4">AGILE_MODBUS_TCP_PRESET_RSP_LENGTH</a>;</div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;}</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160; </div>
<div class="line"><a name="l00114"></a><span class="lineno"><a class="line" href="group___t_c_p___private___functions.html#gae6a11c1140ecb35f8fb1e0b69c902f9b">  114</a></span>&#160;<span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="group___t_c_p___private___functions.html#gae6a11c1140ecb35f8fb1e0b69c902f9b">agile_modbus_tcp_prepare_response_tid</a>(<span class="keyword">const</span> uint8_t *req, <span class="keywordtype">int</span> *req_length)</div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;{</div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;    (void)req_length;</div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;    <span class="keywordflow">return</span> (req[0] &lt;&lt; 8) + req[1];</div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;}</div>
<div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160; </div>
<div class="line"><a name="l00126"></a><span class="lineno"><a class="line" href="group___t_c_p___private___functions.html#ga7913f7526caca2249c83436540654751">  126</a></span>&#160;<span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="group___t_c_p___private___functions.html#ga7913f7526caca2249c83436540654751">agile_modbus_tcp_send_msg_pre</a>(uint8_t *req, <span class="keywordtype">int</span> req_length)</div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;{</div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;    <span class="comment">/* Substract the header length to the message length */</span></div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;    <span class="keywordtype">int</span> mbap_length = req_length - 6;</div>
<div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160; </div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;    req[4] = mbap_length &gt;&gt; 8;</div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;    req[5] = mbap_length &amp; 0x00FF;</div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160; </div>
<div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;    <span class="keywordflow">return</span> req_length;</div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;}</div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160; </div>
<div class="line"><a name="l00144"></a><span class="lineno"><a class="line" href="group___t_c_p___private___functions.html#ga5636ca84a4a90e5b75fc3d2476838a9d">  144</a></span>&#160;<span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="group___t_c_p___private___functions.html#ga5636ca84a4a90e5b75fc3d2476838a9d">agile_modbus_tcp_check_integrity</a>(<a class="code" href="structagile__modbus.html">agile_modbus_t</a> *ctx, uint8_t *msg, <span class="keyword">const</span> <span class="keywordtype">int</span> msg_length)</div>
<div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;{</div>
<div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;    (void)ctx;</div>
<div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;    (void)msg;</div>
<div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;    <span class="keywordflow">return</span> msg_length;</div>
<div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;}</div>
<div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160; </div>
<div class="line"><a name="l00159"></a><span class="lineno"><a class="line" href="group___t_c_p___private___functions.html#ga50d4eafae8f45c41c65aaa1f8b5087c8">  159</a></span>&#160;<span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="group___t_c_p___private___functions.html#ga50d4eafae8f45c41c65aaa1f8b5087c8">agile_modbus_tcp_pre_check_confirmation</a>(<a class="code" href="structagile__modbus.html">agile_modbus_t</a> *ctx, <span class="keyword">const</span> uint8_t *req,</div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;                                                   <span class="keyword">const</span> uint8_t *rsp, <span class="keywordtype">int</span> rsp_length)</div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;{</div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;    (void)ctx;</div>
<div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;    (void)rsp_length;</div>
<div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;    <span class="comment">/* Check transaction ID */</span></div>
<div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;    <span class="keywordflow">if</span> (req[0] != rsp[0] || req[1] != rsp[1])</div>
<div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;        <span class="keywordflow">return</span> -1;</div>
<div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160; </div>
<div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;    <span class="comment">/* Check protocol ID */</span></div>
<div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;    <span class="keywordflow">if</span> (rsp[2] != 0x0 &amp;&amp; rsp[3] != 0x0)</div>
<div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;        <span class="keywordflow">return</span> -1;</div>
<div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160; </div>
<div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;    <span class="keywordflow">return</span> 0;</div>
<div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;}</div>
<div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160; </div>
<div class="line"><a name="l00186"></a><span class="lineno"><a class="line" href="group___t_c_p___private___constants.html#ga9789b18d510d592bc71c6ecdd9b4a4f5">  186</a></span>&#160;<span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="structagile__modbus__backend.html">agile_modbus_backend_t</a> <a class="code" href="group___t_c_p___private___constants.html#ga9789b18d510d592bc71c6ecdd9b4a4f5">agile_modbus_tcp_backend</a> =</div>
<div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160;    {</div>
<div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;        <a class="code" href="group___c_o_m_m_o_n___exported___types.html#gga88d4f826eda73ae5fc071856f70683fdaf4f989f5d3eaf37ca4175e7bd6560714">AGILE_MODBUS_BACKEND_TYPE_TCP</a>,</div>
<div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;        <a class="code" href="group___t_c_p___exported___constants.html#gacae695692d9e813a6606a44fa36b807d">AGILE_MODBUS_TCP_HEADER_LENGTH</a>,</div>
<div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160;        <a class="code" href="group___t_c_p___exported___constants.html#ga12e0bfa5b136035efbb03a7c2885cf8b">AGILE_MODBUS_TCP_CHECKSUM_LENGTH</a>,</div>
<div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;        <a class="code" href="group___t_c_p___exported___constants.html#ga8872b1fc07bcf9f2c723f5f05cded968">AGILE_MODBUS_TCP_MAX_ADU_LENGTH</a>,</div>
<div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;        <a class="code" href="group___t_c_p___private___functions.html#ga5368e75a4d452b51ba973e5cef464752">agile_modbus_tcp_set_slave</a>,</div>
<div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;        <a class="code" href="group___t_c_p___private___functions.html#ga83bcbff089bd342862ecaf44d9bf2e47">agile_modbus_tcp_build_request_basis</a>,</div>
<div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;        <a class="code" href="group___t_c_p___private___functions.html#ga8fb22cc4a73e636d6bb6593d0e60f59c">agile_modbus_tcp_build_response_basis</a>,</div>
<div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;        <a class="code" href="group___t_c_p___private___functions.html#gae6a11c1140ecb35f8fb1e0b69c902f9b">agile_modbus_tcp_prepare_response_tid</a>,</div>
<div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;        <a class="code" href="group___t_c_p___private___functions.html#ga7913f7526caca2249c83436540654751">agile_modbus_tcp_send_msg_pre</a>,</div>
<div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;        <a class="code" href="group___t_c_p___private___functions.html#ga5636ca84a4a90e5b75fc3d2476838a9d">agile_modbus_tcp_check_integrity</a>,</div>
<div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;        <a class="code" href="group___t_c_p___private___functions.html#ga50d4eafae8f45c41c65aaa1f8b5087c8">agile_modbus_tcp_pre_check_confirmation</a>};</div>
<div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160; </div>
<div class="line"><a name="l00217"></a><span class="lineno"><a class="line" href="group___t_c_p___exported___functions.html#ga4f9b3e37c01e6f112f63e7194dad7b33">  217</a></span>&#160;<span class="keywordtype">int</span> <a class="code" href="group___t_c_p___exported___functions.html#ga4f9b3e37c01e6f112f63e7194dad7b33">agile_modbus_tcp_init</a>(<a class="code" href="structagile__modbus__tcp.html">agile_modbus_tcp_t</a> *ctx, uint8_t *send_buf, <span class="keywordtype">int</span> send_bufsz, uint8_t *read_buf, <span class="keywordtype">int</span> read_bufsz)</div>
<div class="line"><a name="l00218"></a><span class="lineno">  218</span>&#160;{</div>
<div class="line"><a name="l00219"></a><span class="lineno">  219</span>&#160;    <a class="code" href="group___c_o_m_m_o_n___exported___functions.html#ga520bd6e5aa1521ebe24a058f8bc9e6f5">agile_modbus_common_init</a>(&amp;(ctx-&gt;<a class="code" href="structagile__modbus__tcp.html#a0609cfbb362720398ab9ab2027acf020">_ctx</a>), send_buf, send_bufsz, read_buf, read_bufsz);</div>
<div class="line"><a name="l00220"></a><span class="lineno">  220</span>&#160;    ctx-&gt;<a class="code" href="structagile__modbus__tcp.html#a0609cfbb362720398ab9ab2027acf020">_ctx</a>.<a class="code" href="structagile__modbus.html#aa9d48739d05877966b473beeb61176b7">backend</a> = &amp;<a class="code" href="group___t_c_p___private___constants.html#ga9789b18d510d592bc71c6ecdd9b4a4f5">agile_modbus_tcp_backend</a>;</div>
<div class="line"><a name="l00221"></a><span class="lineno">  221</span>&#160;    ctx-&gt;<a class="code" href="structagile__modbus__tcp.html#a0609cfbb362720398ab9ab2027acf020">_ctx</a>.<a class="code" href="structagile__modbus.html#ae1ab077d16f51a6dbaaa5e3136cf6053">backend_data</a> = ctx;</div>
<div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160; </div>
<div class="line"><a name="l00223"></a><span class="lineno">  223</span>&#160;    ctx-&gt;<a class="code" href="structagile__modbus__tcp.html#a5e7cd9a4f62bbcade736030cea7f0f56">t_id</a> = 0;</div>
<div class="line"><a name="l00224"></a><span class="lineno">  224</span>&#160; </div>
<div class="line"><a name="l00225"></a><span class="lineno">  225</span>&#160;    <span class="keywordflow">return</span> 0;</div>
<div class="line"><a name="l00226"></a><span class="lineno">  226</span>&#160;}</div>
<div class="line"><a name="l00227"></a><span class="lineno">  227</span>&#160; </div>
<div class="line"><a name="l00236"></a><span class="lineno">  236</span>&#160;<span class="preprocessor">#endif </span><span class="comment">/* AGILE_MODBUS_USING_TCP */</span><span class="preprocessor"></span></div>
<div class="ttc" id="aagile__modbus_8h_html"><div class="ttname"><a href="agile__modbus_8h.html">agile_modbus.h</a></div><div class="ttdoc">Agile Modbus software package common header file.</div></div>
<div class="ttc" id="aagile__modbus__tcp_8h_html"><div class="ttname"><a href="agile__modbus__tcp_8h.html">agile_modbus_tcp.h</a></div><div class="ttdoc">Agile Modbus package TCP header file.</div></div>
<div class="ttc" id="agroup___c_o_m_m_o_n___exported___functions_html_ga520bd6e5aa1521ebe24a058f8bc9e6f5"><div class="ttname"><a href="group___c_o_m_m_o_n___exported___functions.html#ga520bd6e5aa1521ebe24a058f8bc9e6f5">agile_modbus_common_init</a></div><div class="ttdeci">void agile_modbus_common_init(agile_modbus_t *ctx, uint8_t *send_buf, int send_bufsz, uint8_t *read_buf, int read_bufsz)</div><div class="ttdoc">initialize modbus handle</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus_8c_source.html#l00257">agile_modbus.c:257</a></div></div>
<div class="ttc" id="agroup___c_o_m_m_o_n___exported___types_html_gga88d4f826eda73ae5fc071856f70683fdaf4f989f5d3eaf37ca4175e7bd6560714"><div class="ttname"><a href="group___c_o_m_m_o_n___exported___types.html#gga88d4f826eda73ae5fc071856f70683fdaf4f989f5d3eaf37ca4175e7bd6560714">AGILE_MODBUS_BACKEND_TYPE_TCP</a></div><div class="ttdeci">@ AGILE_MODBUS_BACKEND_TYPE_TCP</div><div class="ttdoc">TCP.</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus_8h_source.html#l00167">agile_modbus.h:166</a></div></div>
<div class="ttc" id="agroup___t_c_p___exported___constants_html_ga12e0bfa5b136035efbb03a7c2885cf8b"><div class="ttname"><a href="group___t_c_p___exported___constants.html#ga12e0bfa5b136035efbb03a7c2885cf8b">AGILE_MODBUS_TCP_CHECKSUM_LENGTH</a></div><div class="ttdeci">#define AGILE_MODBUS_TCP_CHECKSUM_LENGTH</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus__tcp_8h_source.html#l00036">agile_modbus_tcp.h:36</a></div></div>
<div class="ttc" id="agroup___t_c_p___exported___constants_html_ga3e02eaed8e08d8e34bccdd785fa09da4"><div class="ttname"><a href="group___t_c_p___exported___constants.html#ga3e02eaed8e08d8e34bccdd785fa09da4">AGILE_MODBUS_TCP_PRESET_RSP_LENGTH</a></div><div class="ttdeci">#define AGILE_MODBUS_TCP_PRESET_RSP_LENGTH</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus__tcp_8h_source.html#l00034">agile_modbus_tcp.h:34</a></div></div>
<div class="ttc" id="agroup___t_c_p___exported___constants_html_ga8872b1fc07bcf9f2c723f5f05cded968"><div class="ttname"><a href="group___t_c_p___exported___constants.html#ga8872b1fc07bcf9f2c723f5f05cded968">AGILE_MODBUS_TCP_MAX_ADU_LENGTH</a></div><div class="ttdeci">#define AGILE_MODBUS_TCP_MAX_ADU_LENGTH</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus__tcp_8h_source.html#l00045">agile_modbus_tcp.h:45</a></div></div>
<div class="ttc" id="agroup___t_c_p___exported___constants_html_gac012bade0617291b78e007393f72b2e8"><div class="ttname"><a href="group___t_c_p___exported___constants.html#gac012bade0617291b78e007393f72b2e8">AGILE_MODBUS_TCP_PRESET_REQ_LENGTH</a></div><div class="ttdeci">#define AGILE_MODBUS_TCP_PRESET_REQ_LENGTH</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus__tcp_8h_source.html#l00033">agile_modbus_tcp.h:33</a></div></div>
<div class="ttc" id="agroup___t_c_p___exported___constants_html_gacae695692d9e813a6606a44fa36b807d"><div class="ttname"><a href="group___t_c_p___exported___constants.html#gacae695692d9e813a6606a44fa36b807d">AGILE_MODBUS_TCP_HEADER_LENGTH</a></div><div class="ttdeci">#define AGILE_MODBUS_TCP_HEADER_LENGTH</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus__tcp_8h_source.html#l00032">agile_modbus_tcp.h:32</a></div></div>
<div class="ttc" id="agroup___t_c_p___exported___functions_html_ga4f9b3e37c01e6f112f63e7194dad7b33"><div class="ttname"><a href="group___t_c_p___exported___functions.html#ga4f9b3e37c01e6f112f63e7194dad7b33">agile_modbus_tcp_init</a></div><div class="ttdeci">int agile_modbus_tcp_init(agile_modbus_tcp_t *ctx, uint8_t *send_buf, int send_bufsz, uint8_t *read_buf, int read_bufsz)</div><div class="ttdoc">TCP initialization.</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus__tcp_8c_source.html#l00217">agile_modbus_tcp.c:217</a></div></div>
<div class="ttc" id="agroup___t_c_p___private___constants_html_ga9789b18d510d592bc71c6ecdd9b4a4f5"><div class="ttname"><a href="group___t_c_p___private___constants.html#ga9789b18d510d592bc71c6ecdd9b4a4f5">agile_modbus_tcp_backend</a></div><div class="ttdeci">static const agile_modbus_backend_t agile_modbus_tcp_backend</div><div class="ttdoc">TCP backend interface.</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus__tcp_8c_source.html#l00186">agile_modbus_tcp.c:186</a></div></div>
<div class="ttc" id="agroup___t_c_p___private___functions_html_ga50d4eafae8f45c41c65aaa1f8b5087c8"><div class="ttname"><a href="group___t_c_p___private___functions.html#ga50d4eafae8f45c41c65aaa1f8b5087c8">agile_modbus_tcp_pre_check_confirmation</a></div><div class="ttdeci">static int agile_modbus_tcp_pre_check_confirmation(agile_modbus_t *ctx, const uint8_t *req, const uint8_t *rsp, int rsp_length)</div><div class="ttdoc">TCP pre-check confirmation interface (compare transaction identifier and protocol identifier)</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus__tcp_8c_source.html#l00159">agile_modbus_tcp.c:159</a></div></div>
<div class="ttc" id="agroup___t_c_p___private___functions_html_ga5368e75a4d452b51ba973e5cef464752"><div class="ttname"><a href="group___t_c_p___private___functions.html#ga5368e75a4d452b51ba973e5cef464752">agile_modbus_tcp_set_slave</a></div><div class="ttdeci">static int agile_modbus_tcp_set_slave(agile_modbus_t *ctx, int slave)</div><div class="ttdoc">TCP set address interface.</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus__tcp_8c_source.html#l00034">agile_modbus_tcp.c:34</a></div></div>
<div class="ttc" id="agroup___t_c_p___private___functions_html_ga5636ca84a4a90e5b75fc3d2476838a9d"><div class="ttname"><a href="group___t_c_p___private___functions.html#ga5636ca84a4a90e5b75fc3d2476838a9d">agile_modbus_tcp_check_integrity</a></div><div class="ttdeci">static int agile_modbus_tcp_check_integrity(agile_modbus_t *ctx, uint8_t *msg, const int msg_length)</div><div class="ttdoc">TCP check receiving data integrity interface.</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus__tcp_8c_source.html#l00144">agile_modbus_tcp.c:144</a></div></div>
<div class="ttc" id="agroup___t_c_p___private___functions_html_ga7913f7526caca2249c83436540654751"><div class="ttname"><a href="group___t_c_p___private___functions.html#ga7913f7526caca2249c83436540654751">agile_modbus_tcp_send_msg_pre</a></div><div class="ttdeci">static int agile_modbus_tcp_send_msg_pre(uint8_t *req, int req_length)</div><div class="ttdoc">TCP pre-send data interface (calculate the value of the length field and store it)</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus__tcp_8c_source.html#l00126">agile_modbus_tcp.c:126</a></div></div>
<div class="ttc" id="agroup___t_c_p___private___functions_html_ga83bcbff089bd342862ecaf44d9bf2e47"><div class="ttname"><a href="group___t_c_p___private___functions.html#ga83bcbff089bd342862ecaf44d9bf2e47">agile_modbus_tcp_build_request_basis</a></div><div class="ttdeci">static int agile_modbus_tcp_build_request_basis(agile_modbus_t *ctx, int function, int addr, int nb, uint8_t *req)</div><div class="ttdoc">TCP builds the basic request message interface (header message)</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus__tcp_8c_source.html#l00049">agile_modbus_tcp.c:49</a></div></div>
<div class="ttc" id="agroup___t_c_p___private___functions_html_ga8fb22cc4a73e636d6bb6593d0e60f59c"><div class="ttname"><a href="group___t_c_p___private___functions.html#ga8fb22cc4a73e636d6bb6593d0e60f59c">agile_modbus_tcp_build_response_basis</a></div><div class="ttdeci">static int agile_modbus_tcp_build_response_basis(agile_modbus_sft_t *sft, uint8_t *rsp)</div><div class="ttdoc">TCP builds a basic response message interface (header message)</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus__tcp_8c_source.html#l00086">agile_modbus_tcp.c:86</a></div></div>
<div class="ttc" id="agroup___t_c_p___private___functions_html_gae6a11c1140ecb35f8fb1e0b69c902f9b"><div class="ttname"><a href="group___t_c_p___private___functions.html#gae6a11c1140ecb35f8fb1e0b69c902f9b">agile_modbus_tcp_prepare_response_tid</a></div><div class="ttdeci">static int agile_modbus_tcp_prepare_response_tid(const uint8_t *req, int *req_length)</div><div class="ttdoc">TCP ready response interface.</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus__tcp_8c_source.html#l00114">agile_modbus_tcp.c:114</a></div></div>
<div class="ttc" id="astructagile__modbus__backend_html"><div class="ttname"><a href="structagile__modbus__backend.html">agile_modbus_backend</a></div><div class="ttdoc">Agile Modbus backend interface structure.</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus_8h_source.html#l00198">agile_modbus.h:198</a></div></div>
<div class="ttc" id="astructagile__modbus__sft_html"><div class="ttname"><a href="structagile__modbus__sft.html">agile_modbus_sft</a></div><div class="ttdoc">contains the modbus header parameter structure</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus_8h_source.html#l00187">agile_modbus.h:187</a></div></div>
<div class="ttc" id="astructagile__modbus__sft_html_ab9ada92752df1ac2d7597a43eb1cd374"><div class="ttname"><a href="structagile__modbus__sft.html#ab9ada92752df1ac2d7597a43eb1cd374">agile_modbus_sft::slave</a></div><div class="ttdeci">int slave</div><div class="ttdoc">slave address</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus_8h_source.html#l00188">agile_modbus.h:188</a></div></div>
<div class="ttc" id="astructagile__modbus__sft_html_aea219d53ef291aa545de54ed04ecc639"><div class="ttname"><a href="structagile__modbus__sft.html#aea219d53ef291aa545de54ed04ecc639">agile_modbus_sft::t_id</a></div><div class="ttdeci">int t_id</div><div class="ttdoc">Transaction identifier.</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus_8h_source.html#l00190">agile_modbus.h:190</a></div></div>
<div class="ttc" id="astructagile__modbus__sft_html_afe1918bcff8e86066656a68de876b873"><div class="ttname"><a href="structagile__modbus__sft.html#afe1918bcff8e86066656a68de876b873">agile_modbus_sft::function</a></div><div class="ttdeci">int function</div><div class="ttdoc">function code</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus_8h_source.html#l00189">agile_modbus.h:189</a></div></div>
<div class="ttc" id="astructagile__modbus__tcp_html"><div class="ttname"><a href="structagile__modbus__tcp.html">agile_modbus_tcp</a></div><div class="ttdoc">TCP structure.</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus__tcp_8h_source.html#l00057">agile_modbus_tcp.h:57</a></div></div>
<div class="ttc" id="astructagile__modbus__tcp_html_a0609cfbb362720398ab9ab2027acf020"><div class="ttname"><a href="structagile__modbus__tcp.html#a0609cfbb362720398ab9ab2027acf020">agile_modbus_tcp::_ctx</a></div><div class="ttdeci">agile_modbus_t _ctx</div><div class="ttdoc">modbus handle</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus__tcp_8h_source.html#l00058">agile_modbus_tcp.h:58</a></div></div>
<div class="ttc" id="astructagile__modbus__tcp_html_a5e7cd9a4f62bbcade736030cea7f0f56"><div class="ttname"><a href="structagile__modbus__tcp.html#a5e7cd9a4f62bbcade736030cea7f0f56">agile_modbus_tcp::t_id</a></div><div class="ttdeci">uint16_t t_id</div><div class="ttdoc">Extract from MODBUS Messaging on TCP/IP Implementation Guide V1.0b (page 23/46): The transaction iden...</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus__tcp_8h_source.html#l00059">agile_modbus_tcp.h:59</a></div></div>
<div class="ttc" id="astructagile__modbus_html"><div class="ttname"><a href="structagile__modbus.html">agile_modbus</a></div><div class="ttdoc">Agile Modbus structure.</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus_8h_source.html#l00217">agile_modbus.h:217</a></div></div>
<div class="ttc" id="astructagile__modbus_html_aa9d48739d05877966b473beeb61176b7"><div class="ttname"><a href="structagile__modbus.html#aa9d48739d05877966b473beeb61176b7">agile_modbus::backend</a></div><div class="ttdeci">const agile_modbus_backend_t * backend</div><div class="ttdoc">Backend interface.</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus_8h_source.html#l00227">agile_modbus.h:227</a></div></div>
<div class="ttc" id="astructagile__modbus_html_acd02aacf2081b397ee378e21858b2dd7"><div class="ttname"><a href="structagile__modbus.html#acd02aacf2081b397ee378e21858b2dd7">agile_modbus::slave</a></div><div class="ttdeci">int slave</div><div class="ttdoc">slave address</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus_8h_source.html#l00218">agile_modbus.h:218</a></div></div>
<div class="ttc" id="astructagile__modbus_html_ae1ab077d16f51a6dbaaa5e3136cf6053"><div class="ttname"><a href="structagile__modbus.html#ae1ab077d16f51a6dbaaa5e3136cf6053">agile_modbus::backend_data</a></div><div class="ttdeci">void * backend_data</div><div class="ttdoc">Backend data, pointing to RTU or TCP structure.</div><div class="ttdef"><b>Definition:</b> <a href="agile__modbus_8h_source.html#l00228">agile_modbus.h:228</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="agile__modbus__tcp_8c.html">agile_modbus_tcp.c</a></li>
    <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1 </li>
  </ul>
</div>
</body>
</html>
